package com.woniuxy.dao;

import com.woniuxy.entity.DTO.ShopProductsDTO;
import com.woniuxy.entity.ShopProducts;
import org.apache.ibatis.annotations.*;
import org.springframework.data.domain.Pageable;
import java.util.List;

/**
 * (ShopProducts)表数据库访问层
 *
 * @author makejava
 * @since 2025-07-10 11:54:56
 */
@Mapper
public interface ShopProductsDao {
    /** 查询所有商品*/
    @Select("select * from shop_products")
    @Results({
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime"),
            @Result(column = "is_hot", property = "isHot"),
            @Result(column = "is_recommend", property = "isRecommend"),
    })
    List<ShopProducts> findAll();

    /** 查询热销商品*/
    @Select("select * from shop_products where is_hot=#{id}")
    @Results({
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime"),
            @Result(column = "is_hot", property = "isHot"),
            @Result(column = "is_recommend", property = "isRecommend"),
    })
    List<ShopProducts> queryHotSalesById(Integer id);

    /** 查询秒杀商品*/
    @Select("select * from shop_products where is_recommend=#{id}")
    @Results({
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime"),
            @Result(column = "is_hot", property = "isHot"),
            @Result(column = "is_recommend", property = "isRecommend"),
    })
    List<ShopProductsDTO> queryKillSalesById(Integer id);

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    ShopProducts queryById(Long id);

    /**
     * 查询指定行数据
     *
     * @param shopProducts 查询条件
     * @param pageable         分页对象
     * @return 对象列表
     */
    List<ShopProducts> queryAllByLimit(ShopProducts shopProducts, @Param("pageable") Pageable pageable);

    /**
     * 统计总行数
     *
     * @param shopProducts 查询条件
     * @return 总行数
     */
    long count(ShopProducts shopProducts);

    /**
     * 新增数据
     *
     * @param shopProducts 实例对象
     * @return 影响行数
     */
    int insert(ShopProducts shopProducts);

    /**
     * 批量新增数据（MyBatis原生foreach方法）
     *
     * @param entities List<ShopProducts> 实例对象列表
     * @return 影响行数
     */
    int insertBatch(@Param("entities") List<ShopProducts> entities);

    /**
     * 批量新增或按主键更新数据（MyBatis原生foreach方法）
     *
     * @param entities List<ShopProducts> 实例对象列表
     * @return 影响行数
     * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常，请自行校验入参
     */
    int insertOrUpdateBatch(@Param("entities") List<ShopProducts> entities);

    /**
     * 修改数据
     *
     * @param shopProducts 实例对象
     * @return 影响行数
     */
    int update(ShopProducts shopProducts);

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 影响行数
     */
    int deleteById(Long id);

}

